#pragma once


#include <IXButton.h>
#include <IXButtonDraw.h>
#include "XFrameImpl.h"

typedef enum
{
    BI_Normal = 0,
    BI_Hover,
    BI_Down,
    BI_Disable,
} ButtonImageIndex;

template <class I>
class CXButtonImpl : public CXFrameImpl<I>
{
    typedef CXFrameImpl<I> superclass;

    BEGIN_DEF_SKIN_CLASS(CXButton, superclass, gs_strGuidXSkin)
        IMP_BASIC_INTF(IXButton,    0)
    END_DEF_SKIN_CLASS();

    IMPL_CONTROL_OBJ(CXButtonImpl, superclass, _T("Button"));

public:
    CXButtonImpl();
    virtual ~CXButtonImpl();

public:
    // IXButton
    virtual HRESULT STDMETHODCALLTYPE   put_Draw(IN IXButtonDraw* pDraw);

    virtual HRESULT STDMETHODCALLTYPE   put_ImagePath(IN LPCTSTR szXNC, IN INT nHCount, IN INT nVCount, IN ImageDrawParams* pParam);
    virtual HRESULT STDMETHODCALLTYPE   get_ImagePath(OUT BSTR* pbstrXNC, OUT INT* pnHCount, OUT INT* pnVCount, OUT ImageDrawParams* pParam);

    virtual HRESULT STDMETHODCALLTYPE   put_DrawParams(IN ImageDrawParams* pParam);
    virtual HRESULT STDMETHODCALLTYPE   get_DrawParams(OUT ImageDrawParams* pParam);

    virtual HRESULT STDMETHODCALLTYPE   put_AlphaMode(IN eImageAlphaMode nAlphaMode);
    virtual HRESULT STDMETHODCALLTYPE   get_AlphaMode(OUT eImageAlphaMode* pnAlphaMode);

    virtual HRESULT STDMETHODCALLTYPE   put_AlphaValue(IN BYTE byAlphaValue);
    virtual HRESULT STDMETHODCALLTYPE   get_AlphaValue(OUT LPBYTE pbyAlphaValue);

    virtual HRESULT STDMETHODCALLTYPE   put_TransparentColor(IN COLORREF clrTrans);
    virtual HRESULT STDMETHODCALLTYPE   get_TransparentColor(OUT LPCOLORREF pclrTrans);

public:
    // IXFrame
    virtual void    STDMETHODCALLTYPE   GetAutoSize(OUT LPSIZE pAutoSize);
    virtual void    STDMETHODCALLTYPE   Draw(XCANVAS xCanvas, const RECT& rcDraw);

    virtual BOOL    STDMETHODCALLTYPE   OnMouseDown(IN POINT* pt);
    virtual BOOL    STDMETHODCALLTYPE   OnMouseUp(IN POINT* pt);

    virtual BOOL    STDMETHODCALLTYPE   OnMouseMove(IN POINT* pt);
    virtual BOOL    STDMETHODCALLTYPE   OnMouseHover(IN POINT* pt);
    virtual BOOL    STDMETHODCALLTYPE   OnMouseLeave(IN POINT* pt);

    virtual BOOL    OnKeyDown(UINT uChar, UINT nRepCnt, UINT nFlags);
    virtual BOOL    OnKeyUp(UINT uChar, UINT nRepCnt, UINT nFlags);
public:
    // IXConfig
    virtual void    STDMETHODCALLTYPE   SetEnable(BOOL bEnable);

public:
    // IXBaseObj
    virtual void STDMETHODCALLTYPE   OnFinalRelease();

protected:
    // CXButtonImpl
    void    UpdateImageIndex();
    void    NeedImage();

    virtual void OnImageChanged();

protected:
    IXButtonDraw*   m_pButtonDraw;
};


class CXButton : public CXButtonImpl<IXButton>
{
};
